package com.qingfeng.okms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qingfeng.base.controller.BaseController;
import com.qingfeng.entity.MyResponse;
import com.qingfeng.entity.system.Organize;
import com.qingfeng.entity.system.SystemUser;
import com.qingfeng.entity.system.okms.AamsDepartment;
import com.qingfeng.okms.service.IDepartmentService;
import com.qingfeng.system.service.IOrganizeService;
import com.qingfeng.utils.PageData;
import com.qingfeng.utils.Verify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.*;

/**
 * @author cb
 * @Description TODO
 * @date 2023/6/14
 */

@RestController
@RequestMapping("/okms/department")
public class DepartmentController extends BaseController {
    @Autowired
    private IDepartmentService departmentService;

    @GetMapping("/getTreeList")
    public MyResponse getTreeList(AamsDepartment aamsDepartment) throws IOException {
        //处理数据权限
        String userParams = SecurityContextHolder.getContext().getAuthentication().getName();
        String user_id = userParams.split(":")[1];
//        String organize_id = userParams.split(":")[2];
//        PageData pd = new PageData();
//        pd.put("user_id",user_id);
//        PageData orgPd = userService.findUserOrganizeInfo(pd);
//        List<String> auth_organize_ids = new ArrayList<String>();
//        if(Verify.verifyIsNotNull(orgPd)){
//            if(Verify.verifyIsNotNull(orgPd.get("authOrgIds"))){
//                auth_organize_ids = Arrays.asList(orgPd.get("authOrgIds").toString().split(","));
//            }
//        }
//        organize.setAuth_user(user_id);
//        organize.setAuth_organize_ids(auth_organize_ids);
//        //获取用户
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("id",user_id);
//        SystemUser user = userService.getOne(queryWrapper);
//        if(!user.getType().equals("0")){//管理员
//            organize.setOrg_cascade(orgPd.get("org_cascade").toString());
//        }
        List<AamsDepartment> list = departmentService.findList(aamsDepartment);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list",list);
        return new MyResponse().data(map);
    }

}
